<div class="open-form">
    <div class="open-model">
        <div class="open-auto">
            <button class="layui-btn" id="isCheckFun" style="border-radius: 4px;margin-bottom: 10px">确认选择</button>
            <table id="orderDetailProductFormTable"></table>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
        </div>
    </div>
</div>

<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl'], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        const nowData = {...parentData};
        let cacheList = nowData.cacheList;
        let orderId = nowData.orderId;
        var len=[]
        table.render({
            elem: '#orderDetailProductFormTable',
            url: config.base + `warehouse/warehouse/orderDetail/list`,
            where: {notInListIds: nowData.notInListIds ,orderId: orderId},
            page: true,
            cellMinWidth: 100,
            
            cols: [[
                {
                    title: "<input type='checkbox' id='siam_all' name='siam_all' title='' lay-skin='primary' lay-filter='siam_all'> ",
                    templet: function (d) {
                        if(d.remainingQuantity <=0){//给性别为男的添加复选框
                            return "<input type='checkbox' disabled name='siam_one' title='' lay-skin='primary' data-value = '"+JSON.stringify(d)+"' lay-filter='siam_one'>";
                        }else {
                            return "<input type='checkbox' name='siam_one' title='' lay-skin='primary' data-value = '"+JSON.stringify(d)+"' lay-filter='siam_one'>";
                        }
                    }
                }
                ,{field: 'productCode', title: '客户产品料号编码', align: 'center'}
                ,{field: 'productName',title: '客户产品名称', align: 'center'}
                ,{field: 'productSpecCode', title: '客户规格码', align: 'center'}
                ,{field: 'productType', title: '产品类型' , align: 'center'}
                ,{field: 'productCategory', title: '所属分类' , align: 'center'}
                ,{field: 'productProducer', title: '厂家' , align: 'center'}
                ,{field: 'productMark', title: '牌号' , align: 'center'}
                ,{field: 'productMainUnit', title: '计量单位' , align: 'center'}
                ,{field: 'productWidth', title: '宽度mm' , align: 'center'}
                ,{field: 'productLength', title: '长度mm' , align: 'center'}
                ,{field: 'diameter', title: '厚度mm' , align: 'center'}
                ,{field: 'netWeight', title: '净重' , align: 'center'}
                ,{field: 'grossWeight', title: '毛重' , align: 'center'}
                ,{field: 'remainingQuantity', title: '剩余发货数量' , align: 'center'}
                ,{field: 'customer', title: '所属客户' , align: 'center'}
                ,{field: 'orderDetailCode', title: '订单详情编号' , align: 'center',hide:true}
            ]],
            done: function (res, curr, count) {
                var that = this.elem.next();
                res.data.forEach(function (item, index) {
                    if (item.remainingQuantity <=0) {
                        var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                        tr.css("background-color", "#e0e0e066");
                    }else{
                        len.push(item)
                    }
                });
            }
        });
        /*全选*/
        form.on("checkbox(siam_all)", function () {
            var status = $(this).prop("checked");
            $.each($("input[name=siam_one]"), function (i, value) {
                if(!$(this).attr("disabled")){
                    $(this).prop("checked", status);
                }

            });
            form.render();
        });

        //有一个未选中全选取消选中
        form.on('checkbox(siam_one)', function () {
            $.each($("input[name=siam_one]"), function () {
                if($(this).prop("checked") == false){
                    $("#siam_all").prop("checked", false);
                    form.render('checkbox');
                    return false;
                }
            });
            //如果都勾选上，勾上全选按钮
            var checkLen = len.length;
            $.each($("input[name=siam_one]"), function () {
                if($(this).prop("checked") == true){
                    checkLen--;
                }
            });
            if(checkLen == 0){
                $("#siam_all").prop("checked", true);
                form.render('checkbox');
            }
        });


        $('#isCheckFun').click(() => {
            var ids = [];
            $.each($("input[name=siam_one]:checked"), function (i, value) {
                ids[i] = JSON.parse($(this).attr("data-value"));
            });
            console.log(ids,"ids")
            if (typeof parent.layui !== 'undefined') {
                childData.list = ids.map(v => {
                    v.productDetailId = v.id;
                    v.warehousePrice = v.price;
                    delete v.id
                    return v
                })
                console.log('childData', ids)
                layer.close(parentData.zindex); // 关闭指定的弹窗
            }
        })
        // $('#isCheckFun').click(() => {
        //     var checkStatus = table.checkStatus('orderDetailProductFormTable');
        //     var data = checkStatus.data;  // 选中的数据
        //     if (typeof parent.layui !== 'undefined') {
        //         childData.list = data.map(v => {
        //             v.productDetailId = v.id;
        //             v.warehousePrice = v.price;
        //             delete v.id
        //             return v
        //         })
        //         console.log('childData', data)
        //         layer.close(parentData.zindex); // 关闭指定的弹窗
        //     }
        // })

    })
</script>